package com.maltys.greedy;

/**
 * @author malty
 * @link <a href="https://leetcode.cn/problems/jump-game/">跳跃游戏</a>
 */
public class JumpGame {
    public boolean canJump(int[] nums) {
        int maxLen = 0;
        for (int i = 0; i <= maxLen; i++) {
            maxLen = Math.max(maxLen, i + nums[i]);
            if (maxLen >= nums.length - 1) {
                return true;
            }
        }
        return false;
    }

    public static void main(String[] args) {
        JumpGame jumpGame = new JumpGame();
        boolean canJump = jumpGame.canJump(new int[]{2, 3, 1, 1, 4});
        System.out.println(canJump);
    }
}
